package com.cobo.fitness.web.fitness.trans;

import com.cobo.fitness.web.fitness.entity.Exercise;
import com.cobo.fitness.web.fitness.entity.Instruction;
import com.cobo.fitness.web.fitness.entity.SecondaryMuscle;
import com.cobo.fitness.web.fitness.vo.ExerciseResVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface ExerciseMapper {

    ExerciseMapper INSTANCE = Mappers.getMapper( ExerciseMapper.class );

    @Mappings({
            @Mapping(target = "instructions", source = "instructionList")
            ,@Mapping(target = "secondaryMuscles", source = "secondaryMuscleList")
    })
    ExerciseResVo exerciseAndInstructionAndSecondaryMuscleToExerciseResVo(Exercise exercise,
                                                                          List<Instruction> instructionList, List<SecondaryMuscle> secondaryMuscleList);


    default String[] mapInstructionList(List<Instruction> instructionList) {
        if (instructionList == null) {
            return new String[0];
        }
        String[] temps = new String[instructionList.size()];
        for (int i = 0; i < instructionList.size(); i++) {
            temps[i] = instructionList.get(i).getContentCn().trim();
        }
        return temps;
    }

    default String[] mapSecondaryMuscleList(List<SecondaryMuscle> secondaryMuscleList) {
        if (secondaryMuscleList == null) {
            return new String[0];
        }
        String[] temps = new String[secondaryMuscleList.size()];
        for (int i = 0; i < secondaryMuscleList.size(); i++) {
            temps[i] = secondaryMuscleList.get(i).getContentCn().trim();
        }
        return temps;
    }

}
